import nodemailer from "nodemailer";
import Mail from "nodemailer/lib/mailer";
import { logger } from "@/utils/log"; // 日志方法
const transporter = nodemailer.createTransport({
  host: "xxxx",
  port: 465,
  secure: true,
  service: "qq",
  auth: {
    user: "xx@xx.com",
    pass: "xxxxx", // 授权码
  },
});

// 发送邮件方法
export const sendEmail = async (options: Mail.Options) => {
  return new Promise((resolve, reject) => {
    transporter.sendMail(options, (error, data) => {
      if (error) {
        reject({ message: "邮箱发送失败", error });
      } else {
        resolve(data);
        logger.log("邮件发送成功");
      }
    });
  });
};
